package com.rexense.beacon.controller;

import com.rexense.beacon.entity.Msg;
import com.rexense.beacon.service.MsgService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/beacon")
public class BeaconController {

    @Autowired
    private MsgService msgService;

    @RequestMapping("/put")
    public Object putMsg(@RequestBody Msg msg) {
        msgService.receive(msg);
        return "OK";
    }


    @CrossOrigin(origins = "*", maxAge = 3600)
    @RequestMapping("/mock")
    public Object mock(@RequestParam double x, @RequestParam double y) {
        System.out.println("================================================");
        System.out.println(x + ", " + y);
        System.out.println("================================================");
        return "ok";
    }

    @CrossOrigin(origins = "*", maxAge = 3600)
    @RequestMapping("/mock/msg")
    public Object mock(@RequestParam String id, @RequestParam double rssi, @RequestParam String msgId, @RequestParam String labelId) {
        msgService.receive(
                Msg.builder()
                        .beaconId(id)
                        .labelId(labelId)
                        .msgId(msgId)
                        .rssi(rssi)
                        .build()
        );
        return "ok";
    }

}
